home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0057_Roman-Decimal Conversion.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  959b  |  47 lines

  1. {
  2. >I would like to know if there is a function to convert a year to Roman
  3. >Numerals (1993 to MCMCMIII).
  4.  
  5.  Brian Pape, Brian Grammer, Mike Lazar, Christy Reed, Matt Hayes
  6. }
  7.  
  8. program roman;
  9.  
  10. const
  11.   num   = 'IVXLCDM';
  12.   value : array [1..7] of integer = (1, 5, 10, 50, 100, 500, 1000);
  13. var
  14.   i   : byte;
  15.   s   : string;
  16.   sum : integer;
  17. begin
  18.   writeln('Enter the Roman Numerals: ');
  19.   readln(s);
  20.   i := length(s);
  21.   while (i >= 1) do
  22.   begin
  23.     if i > 1 then
  24.     begin
  25.       if pos(s[i], num) <= (pos(s[i - 1], num)) then
  26.       begin
  27.         sum := sum + value[pos(s[i], num)];
  28.         dec(i);
  29.       end
  30.       else
  31.       begin
  32.         sum := sum + value[pos(s[i],num)] - value[pos(s[i - 1], num)];
  33.         dec(i, 2);
  34.       end;
  35.     end
  36.     else
  37.     begin
  38.       sum := sum + value[pos(s[1], num)];
  39.       dec(i);
  40.     end;
  41.   end;
  42.   WRITELN;
  43.   writeln('Roman numeral: ', s);
  44.   writeln(' Arabic value: ', sum);
  45. end.
  46.  
  47.